package com.springsecurity.config;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.springsecurity.common.vo.AjaxResponseBody;

@Component
public class AjaxAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        AjaxResponseBody responseBody = new AjaxResponseBody();

        responseBody.setStatus("200");
        responseBody.setMsg("Login Success!");

		/*
		 * SelfUserDetails userDetails = (SelfUserDetails)
		 * authentication.getPrincipal();
		 * 
		 * String jwtToken = JwtTokenUtil.generateToken(userDetails.getUsername(), 300,
		 * "_secret"); responseBody.setJwtToken(jwtToken);
		 */

        httpServletResponse.getWriter().write(JSON.toJSONString(responseBody));
    }
}

